package com.corex.vinayak;

import java.io.IOException;

import com.aternity.sdk.Aternity;
import com.corex.vinayak.views.LoginScreen;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.Toast;

public class VinayakActivity extends Activity {
	private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
	private final static String SENDER_ID = "485938436404";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_vinayak);
		//LoginTransaction loginTransaction = new LoginTransaction();


        switch(Aternity.getInstance().init(getApplicationContext(), R.raw.config)) {
            case OK:
                Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();
                break;
            case CONFIGURATION_LOADED_WITH_WARNINGS:
                Toast.makeText(getApplicationContext(),"Warnings",Toast.LENGTH_SHORT).show();
                break;
            //SDK failed to initialize
            case CANNOT_LOAD_CONFIGURATION:
            case INVALID_CONFIGURATION_CONTENT:
                Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
        }
        NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        manager.cancel(1);
		if (savedInstanceState == null) {
			getFragmentManager().beginTransaction()
					.add(R.id.container, new LoginScreen()).commit();
		}

        /*
        final GauseView gv=(GauseView)findViewById(R.id.gauseView1);
        /*
        gv.setBackgroundResource(R.drawable.gaugeback_image);
        gv.setNeedleBackgroundResource(R.drawable.needle_image);
        */
        /*
        gv.setDiameter(460);
        gv.createNeedle(50,230,0,-20);
        gv.setAngleRange(45,315);
		gv.setCurrentAngle(150);
        */
		/*
		if(checkPlayService()){
			registerInBackground();
		}
		*/
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	public boolean checkPlayService(){
		int isServiceAvail = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
		if (isServiceAvail != ConnectionResult.SUCCESS) {
			 if (GooglePlayServicesUtil.isUserRecoverableError(isServiceAvail)) {
		            GooglePlayServicesUtil.getErrorDialog(isServiceAvail, this,
		                    PLAY_SERVICES_RESOLUTION_REQUEST).show();
		        } else {
		            Log.i("TAG", "This device is not supported.");
		            finish();
		        }
			 return false;
		}else{
			return true;
		}
	}
	
	@SuppressWarnings({  "unchecked", "rawtypes" })
	private void registerInBackground() {
	    new AsyncTask() {

			@Override
			protected Object doInBackground(Object... arg0) {
				// TODO Auto-generated method stub
				GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
				 try {
					String msg = gcm.register(SENDER_ID);
				} catch (IOException e) {
					e.printStackTrace();
				}
				return null;
			}
	    	
	    }.execute(null,null,null);
	}
}
